import { useEffect, useState } from "react";
import { getChannelAPI } from "../apis/article";
import type { Channel } from "../apis/article";
function useChannel() {
  //1. 获取频道列表
  const [channelList, setChannelList] = useState<Channel[]>([]);
  useEffect(() => {
    //1.封装函数 在函数体内调用接口
    const getChannelList = async () => {
      const res = await getChannelAPI();
      setChannelList(res.data.channels);
    };
    getChannelList();
  }, []);
  //2. 把组件中要用到的数据return出去
  return { channelList };
}

export { useChannel };
